#include <iostream>
using namespace std;

void insertionSort(int arr[], int len) {
    if (arr == nullptr || len < 2) {
        return;
    }
    for (int i = 1; i < len; i++) {
        for (int j = i - 1; arr[j] > arr[j + 1] && j >= 0; j--) {
            arr[j] = arr[j] ^ arr[j + 1];
            arr[j + 1] = arr[j] ^ arr[j + 1];
            arr[j] = arr[j] ^ arr[j + 1];
        }
    }
}

void bubbleSort(int arr[], int len) {
    if (arr == nullptr || len < 2) {
        return;
    }
    for (int i = len - 1; i > 0; i--) {
        for (int j = 0; j < i; j++) {
            if (arr[j] > arr[j + 1]) {
                arr[j] = arr[j] ^ arr[j + 1];
                arr[j + 1] = arr[j] ^ arr[j + 1];
                arr[j] = arr[j] ^ arr[j + 1];
            }
        }
    }
}

void selectionSort(int arr[], int len) {
    if (arr == nullptr || len < 2) {
        return;
    }
    for (int i = 0; i < len - 1; i++) {
        int minIndex = i;
        for (int j = i + 1; j < len; j++) {
            minIndex = arr[minIndex] < arr[j] ? minIndex : j;
        }
        if (minIndex != i) {
            arr[minIndex] = arr[minIndex] ^ arr[i];
            arr[i] = arr[minIndex] ^ arr[i];
            arr[minIndex] = arr[minIndex] ^ arr[i];
        }
    }
}

void printArray(int* arr, int len) {
    if (arr == nullptr) {
        return;
    }
    cout << "[" << arr[0] << ", ";
    for (int i = 1; i < len; i++) {
        cout << "," << arr[i];
    }
    cout << "]";
}

int main() {
    int arr[] = {592, 45, 87934, 89789, 1, 2, 234, 5464, 7867};
    int len = sizeof(arr) / sizeof(arr[0]);
    printArray(arr, len);
    cout << endl;
    insertionSort(arr, len);
    printArray(arr, len);


    return 0;
}